package com.lxy.skill.controller;

import com.alibaba.fastjson.JSONObject;
import com.lxy.skill.server.SecKillServer;
import com.lxy.skill.util.RedisUtil;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Author lxy
 * @Date 2021/12/10 15:06
 * @Description
 */

@RestController
@RequestMapping(value = "/server")
public class SecKillServerController {

    @Autowired
    private SecKillServer secKillServer;

    @PostMapping("/seckill")
    public Boolean skill(@RequestParam(value="sid", required = false) String sid,@RequestParam(value = "uid", required = false) String uid){
        System.out.println("访问的秒杀服务是8033，请求的时间："+new Date()+" sid="+sid+" uid="+uid);
        boolean b = secKillServer.skillRedisson(sid, uid);

//        try {
//            boolean b = secKillServer.skillZookeeper(sid, uid);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return b;
    }
}

